﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Battle
{
    class FadeDisplay
    {
        // Subspace command to start to toggle lvz
        private string BaseCommand = "*objset ";

        private int[] _LvzBaseIDs = new int[] { };
        /// <summary>
        /// Set all the base IDs for your lvz here - they are the object ids in your lvz
        /// The score should look like ->       000000001234
        /// base ids should start from left side^ to right ^
        /// so if you have a score with max 10 digits you will have 12 base id's
        /// </summary>
        public int[] LvzBaseIDs
        {
            get { return _LvzBaseIDs; }
            set { _LvzBaseIDs = value; }
        }

        /// <summary>
        /// Returns the string command to toggle lvz for old image and new image
        /// If you are using to update a decimal score,
        /// make sure to multiply it to take out decimal
        /// Example you are using currency and your value is 10.23
        /// Multiply by 100 to get 1023 from it.
        /// </summary>
        /// <param name="OldScore">Old player score</param>
        /// <param name="NewScore">New pleyer score</param>
        /// <returns></returns>
        public string FadeScoreCommand(bool Add, int Score)
        {
            // include lvz command in string
            string LvzCommand = BaseCommand;

            string pos = "+90,";
            string neg = "+91,";

            if (Add)
                LvzCommand += pos;
            else
                LvzCommand += neg;

            LvzCommand += "+93,";
            LvzCommand += "+92,";

            int index = LvzBaseIDs.Length - Score.ToString().PadLeft(3,'0').Length;

            // Make it include 0's if the number is too small, and seperate it into an array
            char[] converted = Score.ToString().PadLeft(3, '0').ToCharArray();

            // Go through the array and compare old to new
            // if there is a difference toggle old and new gfx
            for (int i = 0; i < converted.Length; i++)
            {
                // Take the next digit out of array
                int next_digit = (_LvzBaseIDs[index + i] + int.Parse(converted[i].ToString()));

                LvzCommand += "+" + next_digit + ",";
            }

            return LvzCommand;
        }
    }
}
